﻿/* 公共弹框*/
var EHRBox = {};
EHRBox.config = { "curBoxID": "" };
EHRBox.ShowBox = function (obj) {
    EHR.ShowDivBox(obj);
    EHRBox.RefreshBorderColor(obj);
}
EHRBox.RefreshBorderColor = function (obj) {
    $(obj+" input").each(function () {
        var me = $(this);
        me.focus(function () {
            me.css("border-color", "#5191ce");
        }).blur(function () {
            me.css("border-color", "#c4c4c4");
        });
    });
    $(obj + "  textarea").each(function () {
        var me = $(this);
        me.focus(function () {
            me.css("border", "1px solid #5191ce");
        }).blur(function () {
            me.css("border", "1px solid #c4c4c4");
        });
    });
}
EHRBox.CloseBox = function (obj) {
    EHR.CloseDivBox(obj);
}
EHRBox.GetBoxHtml = function (option) {
    var existFlag = 0;
    var postData = { "doType": option.doType };
    var divBoxID = "div_" + option.doType.substring(3);
    EHRBox.config.curBoxID = divBoxID;
    if ($("#" + divBoxID).length == 0) {
        $("body").append("<div class='panel_lnp'  id='" + divBoxID + "'></div>");
    }
    if ($("#" + divBoxID).html() == "") {
        $.ajax({
            type: "POST",
            async: false,
            dataType: 'xml',
            url: "../Ajax/Common/GlobalApplicationBoxAjax.aspx",
            data: postData,
            success: function (result) {
                var msgtype = $(result).find("msgtype").eq(0).text();
                var message = $(result).find("message").eq(0).text();
                if (msgtype == "0") {
                    var returninfo = $(result).find("returninfo").eq(0).text();
                    EHR.ShowBox(returninfo);
                    existFlag = -1;
                    return;
                }
                if (message != "") {
                    $("#" + divBoxID).html(message);
                }
            }
        });
    }
    else {
        existFlag = "1";
    }
    if (existFlag == -1) {
        return;
    }
    var style;
    if (option.doType == "GetRmsBoxHtml" || option.doType == "GetIntvVideoBoxHtml") {
        style = { "width": "583px", "height": null };
    }
    else {
        style = { "width": null, "height": null };
    }
    $("#" + divBoxID).css(style);
    EHRBox.ShowBox("#" + divBoxID);
    $("#" + divBoxID).css("height", null);
    if (typeof (option.callback) != "undefined" && existFlag == "0") {
        option.callback();
    }
    if (typeof (option.refreshback) != "undefined" && existFlag == "1") {
        option.refreshback();
    }
}
EHRBox.OpenBox = function (option) {
    EHRBox.GetBoxHtml(option);
}
/* 添加标签/删除标签 start*/
var EHRLabelBox = {};
EHRLabelBox.FetchLabel = function () {
    $("#txt_lbl_title").focus();
    $("#txt_lbl_title").val("");
    var Source = $('#hidLabelSource').val();
    var postData = { "doType": "FetchLabelToHrTmp", "Source": Source };
    EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalLabelRemarkAjaxNew.aspx", postData, EHRLabelBox.FetchLabelCompleteHandle);
}
EHRLabelBox.FetchLabelCompleteHandle = function (result) {
    var msgtype = $(result).find("msgtype").eq(0).text();
    var returninfo = $(result).find("returninfo").eq(0).text();
    if (msgtype == "0") {
        $("#div_labelerror").html(returninfo);
        return;
    }
    $("#div_lbl_titlelist").html(returninfo);
    $("#div_AddLabelBoxHtml").css("height", null);
    EHR.ShowDivBox("#div_AddLabelBoxHtml");
    $("#div_AddLabelBoxHtml").css("height", null);
    $("[id^='commonlabel_']").bind("click", function () {
        $("#txt_lbl_title").val((typeof ($(this)[0].innerText) != "undefined") ? $(this)[0].innerText : $(this)[0].textContent);
    });
}
EHRLabelBox.SaveLabel = function () {
    $("#err_lbl_title").html("");
    $("#err_lbl_title").css("display", "block");
    var label_NameLength = "标签名称最多为6个中文或12个英文字符";
    var label_InputName = "请输入标签名称！";
    var label_Task = "标签";
    if (lang == 'en') {
        label_NameLength = "Label title should be less than six Chinese characters or 12 English characters";
        label_InputName = "Please input label title!";
        label_Task = "Label";
    }
    var strLabelTitle = $("#txt_lbl_title").val();
    if (strLabelTitle == "") {
        $("#err_lbl_title").html(label_InputName);
        return;
    }
    if (EHR.getStrLength(strLabelTitle.replace(/\s/gi, "")) > 12) {
        $("#err_lbl_title").html(label_NameLength, 400);
        $("#err_lbl_title").css("diaplay", "");
        return;
    }
    if (EHR.hasHtmlTag(strLabelTitle)) {
        $("#err_lbl_title").html(common_hasHtmlTag.replace("{0}", label_Task));
        return;
    }
    var UserId = $('#hidUserID').val();
    var Source = $('#hidLabelSource').val();
    var SeqId = $('#hidSeqID').val();  //新增参数 适用于网才内推接口
    if ($('#resumeInc').length > 0 && $('#resumeInc').val() == "1") {
        UserId = popUserIDs;
        SeqId = popSeqIDs;
    }
    else {
        UserId = $('#hidUserID').val();
        SeqId = $('#hidSeqID').val();  //新增参数 适用于网才内推接口
    }
    var strPostdata = { "doType": "SaveLabel", "UserId": UserId, "SeqId": SeqId, "LabelTitle": strLabelTitle, "Source": Source };
    EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalLabelRemarkAjaxNew.aspx", strPostdata, EHRLabelBox.SaveLabelCompleteHandle);
}
EHRLabelBox.SaveLabelCompleteHandle = function (result) {
    var msgtype = $(result).find("msgtype").eq(0).text();
    var returninfo = $(result).find("returninfo").eq(0).text();
    if (msgtype == "1") {
        if ($('#resumeInc').length > 0 && $('#resumeInc').val() == "1" && ("," + popSeqIDs + ",").indexOf("," + $('#hidSeqID').val() + ",") >= 0) {//内推简历详情页面
            var labeltitle = "<span class='delSet'>" + $("#txt_lbl_title").val() + "<a title='" + (varLang == "" ? "删除标签" : "Del Tag") + "' class='icon icon_remove_white' href='javascript:mk_DeleteLabel(1);'></a></span>";
            $("#spanLabelTitle").html(labeltitle);
            $("#spanLabelTitleHead").css("display", "");
        }
        else {
            var seqIds = $('#hidUserID').val();
            if ($('#hidLabelSource').val() == "InnerResume" || $('#hidLabelSource').val() == "InnerResume2")
            { seqIds = $('#hidSeqID').val(); }
            var seqId = seqIds.split(',');
            for (var i in seqId) {
                $('span[name="LABELID_{0}"]'.format(seqId[i])).html($("#txt_lbl_title").val());
            }
        }
        EHRBox.CloseBox("#" + EHRBox.config.curBoxID);
        EHR.ShowBox(returninfo);
    }
    else {
        $("#div_labelerror").html(returninfo);
    }
}
EHRLabelBox.RemoveLabel = function () {
    var UserID = $('#hidUserID').val();
    var SeqId = $('#hidSeqID').val();  //新增参数 适用于网才内推接口
    var Source = $('#hidLabelSource').val();
    var strPostdata = { "doType": "DeleteLabel", "UserID": UserID, "SeqId": SeqId, "Source": Source };
    EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalLabelRemarkAjaxNew.aspx", strPostdata, EHRLabelBox.RemoveLabelCompleteHandle);
}
EHRLabelBox.RemoveLabelCompleteHandle = function (result) {
    var msgType = $(result).find('msgtype').eq(0).text();
    var returnInfo = $(result).find('returninfo').eq(0).text();
    if ('1' == msgType) {
        var seqIds = $('#hidUserID').val();
        if ($('#hidLabelSource').val() == "InnerResume" || $('#hidLabelSource').val() == "InnerResume2")
        { seqIds = $('#hidSeqID').val(); }
        var seqId = seqIds.split(',');
        for (var i in seqId) {
            $('span[name="LABELID_{0}"]'.format(seqId[i])).html('');
        }
    }
    else {
        EHR.ShowBox(returnInfo,300);
    }
}
/* 添加标签/删除标签 end*/
/* 转发 start*/
var EHRForwardBox = {};
EHRForwardBox.GetOwnEmail = function () {
    $("#div_fwd_mailtolist").hide();
    $("#txt_fwd_mailcontent").keyup(function () {
        EHRForwardBox.CheckWordLength();
    });
    $("#div_ForwardBoxHtml").click(function (e) {
        var obj = e.srcElement ? e.srcElement : e.target;
        if (obj.tagName.toLowerCase() == "a" || obj.tagName.toLowerCase() == "i") {
            return;
        }
        $("#div_fwd_mailtolist").hide();
    });
    if (lang == "en") {
        $("#div_ForwardBoxHtml .butDown").css({ "top": "1px", "right": "0px" });
        $("#div_ForwardBoxHtml .useText_info .lineDt_leftinfo:eq(0)").css("line-height", "18px");
        if (ie6) {
            $("#div_ForwardBoxHtml .butDown").css("top", "3px");
        }
        if (window.navigator.userAgent.indexOf("Chrome") > -1) {
            $("#div_ForwardBoxHtml .butDown").css("right", "1px");
        }
    }
    var postData = { "doType": "GetOwnEmail" };
    EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalMailRelatedAjax.aspx", postData, EHRForwardBox.GetOwnEmailCompleteHandle);
}
EHRForwardBox.CheckWordLength = function () {
    var wordlength = $("#txt_fwd_mailcontent").val().length;
    $("#div_mailerror").html("");
    if (wordlength >= 500) {
        wordlength = 500;
        $("#div_mailerror").html(Common_WordsCheck.format(500));
        $("#txt_fwd_mailcontent").val($("#txt_fwd_mailcontent").val().substring(0, 500));
    }
    $("#span_fwd_curword").html(Common_CurrentWords.format(wordlength + "/500"));
}
EHRForwardBox.GetOwnEmailCompleteHandle = function (result) {
    var msgType = $(result).find('msgtype').eq(0).text();
    if (msgType == "0") {
        var returnInfo = $(result).find('returninfo').eq(0).text();
        $("#div_mailerror").html(returnInfo);
        return;
    }
    var userName = $(result).find("username").eq(0).text();
    var userEmail = $(result).find("useremail").eq(0).text();
    $("#txt_fwd_mailcontent").val(Transmit_MailContent);
    $("#txt_fwd_mailtitle").val(Transmit_MailSubject);
    $("#txt_fwd_SynCC").val(userEmail);
    $("#txt_fwd_mailfrom").val(userName);
    $("#span_fwd_curword").html(Common_CurrentWords.format($("#txt_fwd_mailcontent").val().length + "/500"));
    $("#div_ForwardBoxHtml").css("height", null);
    EHR.ShowDivBox("#div_ForwardBoxHtml");
}
EHRForwardBox.FetchExportDivData = function () {
    if ($("#div_fwd_mailtolist").html() == "") {
        var postData = { "doType": "FetchExportDivData" };
        EHR.Common_AsyncHandle("POST", "xml", "Common/GlobalMailRelatedAjax.aspx", postData, EHRForwardBox.FetchExportDivDataCompleteHandle);
    }
    else if ($("#div_fwd_mailtolist").is(":hidden")) {
        $("#div_fwd_mailtolist").show();
    }
    else {
        $("#div_fwd_mailtolist").hide();
    }
}
EHRForwardBox.FetchExportDivDataCompleteHandle = function (result) {
    var msgType = $(result).find('msgtype').eq(0).text();
    if (msgType == "0") {
        var returnInfo = $(result).find('returninfo').eq(0).text();
        $("#div_mailerror").html(returnInfo);
        return;
    }
    var strHtml = "";
    $(result).find("message").each(function (i) {
        var strHruID = $(this).children("hruid").text();
        var strName = $(this).children("name").text();
        var strMail = $(this).children("email").text();
        if (strHruID != "" && strMail != "") {
            strHtml += "<a href='javascript:void(0)'  title='\"" + strName + "\"<" + strMail + ">' id='div_maillist_" + strHruID + "' onclick=\"EHRForwardBox.SetTxtMailTo('" + strMail + "')\">&quot;" + strName + "&quot;&lt;" + strMail + "&gt;</a>";
        }
    });
    $("#div_fwd_mailtolist").html(strHtml);
    $("#div_fwd_mailtolist").css("height", "250px");
    $("#div_fwd_mailtolist").show();
}
EHRForwardBox.SetTxtMailTo = function (mail) {
    var curMail = $("#txt_fwd_mailto").val();
    var strMail = curMail.split(';');
    var count = 0;
    for (var i = 0; i < strMail.length; i++) {
        if ($.trim(strMail[i]) != "") {
            count++;
        }
    }
    if (count >= 3) {
        $("#div_mailerror").html(common_Max);
        return;
    }
    var existEmail = ";" + curMail + ";";
    if (existEmail.indexOf(";" + mail + ";") != -1) {
        $("#div_mailerror").html(common_exisitMail);
        return;
    }
    if ($.trim($("#txt_fwd_mailto").val()) == "") {
        $("#txt_fwd_mailto").val(mail + ";")
    }
    else if (curMail.substring(curMail.length - 1, curMail.length) != ";") {
        $("#txt_fwd_mailto").val($("#txt_fwd_mailto").val() + ";" + mail + ";");
    }
    else {
        $("#txt_fwd_mailto").val($("#txt_fwd_mailto").val() + mail + ";");
    }
    $("#div_mailerror").html("");
    $("#txt_fwd_mailto").attr("title", $("#txt_fwd_mailto").val());
    $("#div_fwd_mailtolist").hide();
}

EHRForwardBox.SendEmail = function () {
    $("#div_mailerror").html("");
    if ($("#txt_fwd_mailto").val().replace(/\s/gi, "").length < 1) {
        $("#div_mailerror").html(C_MailAddess2);
        return;
    }
    $("#txt_fwd_mailto").val($("#txt_fwd_mailto").val().replace(/^[\s]+|[\s]+$/g, "").replace(/^[;]+|[;]+$/g, "")); //去除前后空格及;
    var vals = $("#txt_fwd_mailto").val().split(";");
    if (vals.length > 3)//先判个数
    {
        $("#div_mailerror").html(common_Max);
        return;
    }
    for (var i = 0; i < vals.length; i++) {
        if (vals[i] != "" && !checkEmail(vals[i])) {
            if (vals.length == 1) {
                $("#div_mailerror").html(C_MailAddess2);
                return;
            }
            else {
                $("#div_mailerror").html(common_errMails.replace("{0}", i + 1));
                return;
            }
        }
    }
    var mailfrom = $("#txt_fwd_mailfrom").val();
    if (mailfrom.replace(/\s/gi, "").length < 1) {
        $("#div_mailerror").html(Msg_MailFromIsNull);
        return;
    }
    if (EHR.hasHtmlTag(mailfrom)) {
        $("#div_mailerror").html(common_hasHtmlTag.replace("{0}", SendEmail_EmailFrom));
        return
    }
    if ($("#chk_fwd_SynCC").attr("checked")) {
        if ($("#txt_fwd_SynCC").val().replace(/\s/gi, "").length < 1 || !checkEmail($("#txt_fwd_SynCC").val())) {
            $("#div_mailerror").html(Transmit_SynCCEmail);
            return;
        }
    }
    if (EHR.hasHtmlTag($("#txt_fwd_mailtitle").val())) {
        $("#div_mailerror").html(common_hasHtmlTag.replace("{0}", EmailTitle));
        return
    }
    if (EHR.hasHtmlTag($("#txt_fwd_mailcontent").val())) {
        $("#div_mailerror").html(common_hasHtmlTag.replace("{0}", MailContent));
        return
    }
    var wordlength = $("#txt_fwd_mailcontent").val().length;
    if (wordlength > 500) {
        $("#div_mailerror").html(Common_WordsCheck.format(wordlength));
        return;
    }
    else {
        $("#div_mailerror").html("");
    }
    var userID = $('#hidUserID').val();
    var seqID = $('#hidSeqID').val();
    var postData = {
        doType: 'SaveProcTransmitForTemp',
        seqid: seqID,
        userId: userID,
        folder: 'temp',
        mailTo: $("#txt_fwd_mailto").val(),
        synCC: $("#txt_fwd_SynCC").val(),
        chkSynCC: $("#chk_fwd_SynCC").attr("checked") == true ? 1 : 0,
        content: $("#txt_fwd_mailcontent").val(),
        from: mailfrom,
        title: $("#txt_fwd_mailtitle").val()
    };
    EHR.Common_AsyncHandle("POST", "xml", "GlobalProcTransmitAjax.aspx", postData, EHRForwardBox.SendEmailCompleteHandle);
}
EHRForwardBox.SendEmailCompleteHandle = function (result) {
    var msgtype = $(result).find("msgtype").eq(0).text();
    var returninfo = $(result).find("returninfo").eq(0).text();
    if (msgtype == "1") {
        EHRBox.CloseBox("#" + EHRBox.config.curBoxID);
        EHR.ShowBox(returninfo);
    }
    else {
        $("#div_mailerror").html(returninfo);
    }
}
/* 转发 end*/